import MySQLdb												#导入模块
conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='',db='test')		#连接数据库
cur=conn.cursor()												#创建游标对象
conn.set_character_set('utf8')										#设置字符集
sql="SELECT * FROM STUDENT"									#定义SQL语句
cur.execute(sql)												#执行SQL语句
result=cur.fetchall()												#获取结果
print("删除记录之前表中内容为：")
print("==================================")
for re in result:													#遍历结果
	print(re[0],end="")
	print("\t",re[1],end="")
	print("\t",re[2],end="")
	print("\t",re[3],end="")
	print("\t",re[4])
	print("==================================")
sql_del="DELETE FROM STUDENT WHERE id='4'"
cur.execute(sql_del)
conn.commit()
sql="SELECT * FROM STUDENT"									#定义SQL语句
cur.execute(sql)												#执行SQL语句
result=cur.fetchall()												#获取结果
print("删除记录之后表中内容为：")
print("==================================")
for re in result:													#遍历结果
	print(re[0],end="")
	print("\t",re[1],end="")
	print("\t",re[2],end="")
	print("\t",re[3],end="")
	print("\t",re[4])
	print("==================================")

cur.close()
conn.close()
